package com.nbsaas.boot.customer.rest.convert;

import com.nbsaas.boot.customer.data.entity.CustomerAddress;
import com.nbsaas.boot.customer.api.domain.request.CustomerAddressRequest;

import org.springframework.beans.BeanUtils;
import com.nbsaas.boot.rest.api.Converter;
import com.nbsaas.boot.utils.BeanDataUtils;
            import com.nbsaas.boot.area.data.entity.Area;
            import com.nbsaas.boot.area.data.entity.Area;
            import com.nbsaas.boot.area.data.entity.Area;
            import com.nbsaas.boot.customer.data.entity.Customer;

/**
* 收货地址请求对象转换成实体对象
*/

public class CustomerAddressEntityConvert  implements Converter<CustomerAddress, CustomerAddressRequest> {

    @Override
    public CustomerAddress convert(CustomerAddressRequest source) {
        CustomerAddress result = new CustomerAddress();
        BeanDataUtils.copyProperties(source, result);
                    if(source.getArea()!=null){
                    Area area =new Area();
                    area.setId(source.getArea());
                    result.setArea(area);
                    }
                    if(source.getCity()!=null){
                    Area city =new Area();
                    city.setId(source.getCity());
                    result.setCity(city);
                    }
                    if(source.getProvince()!=null){
                    Area province =new Area();
                    province.setId(source.getProvince());
                    result.setProvince(province);
                    }
                    if(source.getCustomer()!=null){
                    Customer customer =new Customer();
                    customer.setId(source.getCustomer());
                    result.setCustomer(customer);
                    }
        return result;
    }
}

